package cn.bone.gateway.web;

import org.apache.commons.io.IOUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.ServletInputStream;
import javax.servlet.http.HttpServletRequest;
import java.io.IOException;
import java.util.Date;

/**
 * Created by superbone on 2017/3/15.
 */
@RestController
public class DemoController {

    private Logger logger = LoggerFactory.getLogger("测试");

    @RequestMapping("/hello")
    public String hello(){

        return "hello world";
    }

    @RequestMapping(value="/fastjson")
    public DemoUser fastjson(){

        DemoUser user = new DemoUser();
        user.setName("张三");
        user.setId(20);
        user.setDate(new Date());
        logger.info("调用方法fastjson");
        return user;
    }

    @RequestMapping(value="/json",method = RequestMethod.POST)
    public String json(HttpServletRequest request){

        try {
            ServletInputStream inputStream = request.getInputStream();
            String inputStr = IOUtils.toString(inputStream);
            inputStream.close();
            System.out.println(inputStr);
        } catch (IOException e) {
            e.printStackTrace();
        }

        return "";
    }

    @RequestMapping("/aes")
    public String aes(){

        return "";
    }
}
class DemoUser{
    private int id;
    private String name;
    private String address;
    private int age;
    private Date date;
    private Date lastTime;

    public int getId() {
        return id;
    }

    public void setId(int id) {
        this.id = id;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getAddress() {
        return address;
    }

    public void setAddress(String address) {
        this.address = address;
    }

    public int getAge() {
        return age;
    }

    public void setAge(int age) {
        this.age = age;
    }

    public Date getDate() {
        return date;
    }

    public void setDate(Date date) {
        this.date = date;
    }

    public Date getLastTime() {
        return lastTime;
    }

    public void setLastTime(Date lastTime) {
        this.lastTime = lastTime;
    }
}